home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / msdos / 4utils80.zip / DISPLAYK.PAS < prev    next >
Pascal/Delphi Source File  |  1993-12-17  |  12KB  |  404 lines

  1. UNIT DisplayKeyboardAndCursor;
  2. (* ----------------------------------------------------------------------
  3.    Part of 4DESC - A Simple 4DOS File Description Editor
  4.  
  5.        David Frey,         & Tom Bowden
  6.        Urdorferstrasse 30    1575 Canberra Drive
  7.        8952 Schlieren ZH     Stone Mountain, GA 30088-3629
  8.        Switzerland           USA
  9.  
  10.        Code created using Turbo Pascal 7.0, (c) Borland International 1992
  11.  
  12.    DISCLAIMER: This unit is freeware: you are allowed to use, copy
  13.                and change it free of charge, but you may not sell or hire
  14.                this part of 4DESC. The copyright remains in our hands.
  15.  
  16.                If you make any (considerable) changes to the source code,
  17.                please let us know. (send a copy or a listing).
  18.                We would like to see what you have done.
  19.  
  20.                We, David Frey and Tom Bowden, the authors, provide absolutely
  21.                no warranty of any kind. The user of this software takes the
  22.                entire risk of damages, failures, data losses or other
  23.                incidents.
  24.  
  25.    This unit manages displaying messages, switching cursor modes etc.
  26.  
  27.    ----------------------------------------------------------------------- *)
  28.  
  29. INTERFACE USES Crt, Dos, Dmouse;
  30.  
  31. CONST Header1 = '4DESC 1.70 - (c) 1992, 1993 Copyright by David Frey & Tom Bowden ';
  32.       Header2 = 'Portions of code (c) 1993 Robert Juhasz and (c) 1990 Borland Inc.';
  33.  
  34. (* Cursor *)
  35.  
  36. VAR OrigCursor : WORD;
  37.  
  38. (* Color constants for color screens: *)
  39.  
  40. CONST co_StatusFg = Blue;
  41.       co_StatusBg = Cyan;
  42.       co_DirFg    = LightCyan;
  43.       co_SelectFg = Blue;
  44.       co_SelectBg = Cyan;
  45.       co_HighFg   = LightRed;
  46.       co_NormFg   = LightGray;
  47.       co_NormBg   = Blue;
  48.       co_WarnFg   = Yellow;
  49.       co_WarnBg   = Cyan;
  50.  
  51.       (* ...and for monochrome displays: *)
  52.  
  53.       mo_StatusFg = Black;
  54.       mo_StatusBg = LightGray;
  55.       mo_DirFg    = White;
  56.       mo_SelectFg = Black;
  57.       mo_SelectBg = LightGray;
  58.       mo_HighFg   = LightGray;
  59.       mo_NormFg   = LightGray;
  60.       mo_NormBg   = Black;
  61.       mo_WarnFg   = Black;
  62.       mo_WarnBg   = White;
  63.  
  64. VAR   ScreenSize : BYTE;
  65.       ScreenWidth: BYTE;
  66.       MaxLines   : BYTE;
  67.       Monochrome : BOOLEAN;
  68.  
  69. VAR   StatusFg   : BYTE;
  70.       StatusBg   : BYTE;
  71.       DirFg      : BYTE;
  72.       SelectFg   : BYTE;
  73.       SelectBg   : BYTE;
  74.       HighFg     : BYTE;
  75.       NormFg     : BYTE;
  76.       NormBg     : BYTE;
  77.       WarnFg     : BYTE;
  78.       WarnBg     : BYTE;
  79.       _4DOSVer   : STRING[11];
  80.  
  81.       ListCmd    : PathStr;
  82.       NotLeftJust: BOOLEAN;
  83.       FullSize   : BOOLEAN;
  84.       UseHidden  : BOOLEAN;
  85.  
  86. PROCEDURE Abort(msg: STRING);
  87.  
  88. (* Min/Max *)
  89. FUNCTION Min(a,b : INTEGER): INTEGER;
  90. FUNCTION Max(a,b : INTEGER): INTEGER;
  91.  
  92. (* Cursor *)
  93. PROCEDURE SetCursorShape(Cursor: WORD);
  94. FUNCTION  GetCursorShape: WORD;
  95. PROCEDURE ResetCursor(Overwrite: BOOLEAN);
  96.  
  97. (* Screen *)
  98. PROCEDURE Get4DOSVer;
  99. PROCEDURE ChooseColors(Monochrome: BOOLEAN);
  100.  
  101. PROCEDURE ReportError(msg: STRING; FullClipBoard, Changed: BOOLEAN);
  102. PROCEDURE DrawMainScreen(Index,NrOfFiles: WORD);
  103. PROCEDURE DrawStatusLine(Redraw,FullClipboard, Changed: BOOLEAN);
  104. PROCEDURE ShowHelpPage;
  105.  
  106. (* Keyboard *)
  107.  
  108. FUNCTION GetKey: WORD;
  109.  
  110.  
  111. IMPLEMENTATION USES HandleINIFile, StringDateHandling;
  112.  
  113. VAR s   : STRING;
  114.     line: STRING[132];
  115.  
  116. PROCEDURE Abort(msg: STRING);
  117. (* Fatal error, abort the program and return an errorlevel of -1 *)
  118.  
  119. BEGIN
  120.  NormVideo;
  121.  ClrScr;
  122.  Write(msg);
  123.  HALT(255);
  124. END;
  125.  
  126. (*------------------------------------------------------------- Min/Max *)
  127. FUNCTION Min(a,b : INTEGER): INTEGER;
  128.  
  129. BEGIN
  130.  IF a < b THEN Min := a
  131.           ELSE Min := b;
  132. END;
  133.  
  134. FUNCTION Max(a,b : INTEGER): INTEGER;
  135.  
  136. BEGIN
  137.  IF a > b THEN Max := a
  138.           ELSE Max := b;
  139. END;
  140.  
  141.  
  142. (* -------------------------------------------------------- Cursor *)
  143.  
  144. PROCEDURE SetCursorShape(Cursor: WORD); ASSEMBLER;
  145.  
  146. ASM
  147.  mov ah,01h
  148.  mov cx,Cursor
  149.  Int 10h
  150. END;
  151.  
  152. FUNCTION  GetCursorShape: WORD; ASSEMBLER;
  153.  
  154. ASM
  155.  mov ah,03h
  156.  mov bh,0
  157.  Int 10h
  158.  mov ax,cx
  159. END;
  160.  
  161. PROCEDURE ResetCursor(Overwrite: BOOLEAN);
  162.  
  163. VAR Cursor : WORD;
  164.  
  165. BEGIN
  166.  IF Overwrite THEN Cursor := $0007
  167.               ELSE Cursor := $0607;
  168.  SetCursorShape(Cursor);
  169. END; (* ResetCursor *)
  170.  
  171.  
  172. (* -------------------------------------------------------- Screen *)
  173. PROCEDURE Get4DOSVer;
  174.  
  175. VAR Regs    : Registers;
  176.     _4dvmaj : STRING[1];
  177.     _4dvmin : STRING[2];
  178.  
  179.  PROCEDURE DisplayVer;
  180.   BEGIN
  181.    Str(Regs.bl:1,_4dvmaj);
  182.    Str(Regs.bh:2,_4dvmin);
  183.    IF _4dvmin[1] = ' ' THEN _4dvmin[1] := '0';
  184.    _4DOSVer := ' 4DOS ' + _4dvmaj + '.' + _4dvmin + ' ';
  185.   END;
  186.  
  187. BEGIN
  188.  Regs.ax := $D44D;
  189.  Regs.bx := $0;
  190.  Intr($2F,Regs);
  191.  IF Regs.ax = $44DD THEN    (* 4DOS is active *)
  192.   DisplayVer
  193.  ELSE
  194.   BEGIN
  195.    Regs.ax := $E44D;
  196.    Regs.bx := $0;
  197.    Intr($2F,Regs);
  198.    IF Regs.ax = $44EE THEN    (* NDOS is active *)
  199.     BEGIN
  200.      DisplayVer;
  201.      _4DOSVer[2] := 'N';
  202.     END
  203.    ELSE
  204.     _4DOSVer := '───────────';
  205.   END
  206. END;  (* Get4DOSVer *)
  207.  
  208. Procedure CheckKeyOrMouse;
  209.  
  210. Var Key : Word;
  211.  
  212. Begin
  213.   Key := $0000;
  214.   Repeat
  215.     If KeyPressed Then Key := GetKey
  216.     Else
  217.       If MouseLoaded Then
  218.          Begin
  219.            ButtonReleased(Left);
  220.            If ReleaseCount > 0 Then Key := $FF;
  221.            ButtonReleased(Right);
  222.            If ReleaseCount > 0 Then Key := $FF;
  223.          End;
  224.   Until Key <> $0000;
  225. End;  (* CheckKeyOrMouse *)
  226.  
  227. PROCEDURE ReportError(msg: STRING; FullClipBoard, Changed: BOOLEAN);
  228.  
  229. VAR ch : WORD;
  230.  
  231. BEGIN
  232.  TextColor(WarnFg); TextBackGround(WarnBg);
  233.  GotoXY(1,MaxLines);
  234.  IF Length(msg) < ScreenWidth-1 THEN Write(Chars(' ',(ScreenWidth-Length(msg)) div 2));
  235.  Write(msg); ClrEol;
  236.  CheckKeyOrMouse;
  237.  DrawStatusLine(TRUE,FullClipBoard,Changed);
  238. END; (* ReportError *)
  239.  
  240. PROCEDURE DrawStatusLine(Redraw,FullClipboard, Changed: BOOLEAN);
  241.  
  242. BEGIN
  243.  TextBackGround(NormBg);
  244.  IF Redraw THEN
  245.   BEGIN
  246.    TextColor(NormFg);
  247.    GotoXY(1,MaxLines); ClrEol; Write(line);
  248.    GotoXY(3,MaxLines); Write(_4DOSVer);
  249.   END;
  250.  
  251.  GotoXY(76,MaxLines);
  252.  IF FullClipBoard THEN BEGIN TextColor(HighFg); Write('Cut'); END
  253.                   ELSE BEGIN TextColor(NormFg); Write('───'); END;
  254.  
  255.  GotoXY(70,MaxLines);
  256.  IF Changed THEN BEGIN TextColor(HighFg); Write('Edit'); END
  257.             ELSE BEGIN TextColor(NormFg); Write('────'); END;
  258. END; (* DrawStatusLine *)
  259.  
  260. PROCEDURE DrawMainScreen(Index,NrOfFiles: WORD);
  261.  
  262. BEGIN
  263.  TextColor(NormFg); TextBackGround(NormBg);
  264.  ClrScr;
  265.  TextColor(StatusFg); TextBackGround(StatusBg); ClrEol;
  266.  GotoXY(1,1);
  267.  Write(' ESC exits │ ',Chr(24),' or ',Chr(25),' Selects │ F1 Help │',
  268.        ' F2 or F10 Saves │   Line ',Index:5,' of ',NrOfFiles:5,' ');
  269.  DrawStatusLine(TRUE,FALSE,FALSE);
  270. END; (* DrawMainScreen *)
  271.  
  272. PROCEDURE ShowHelpPage;
  273.  
  274. VAR ch, cursor : WORD;
  275.  
  276. BEGIN
  277.  TextBackGround(NormBg);
  278.  ClrScr;
  279.  TextColor(DirFg);
  280.  GotoXY((ScreenWidth-10) DIV 2, 1); Write('4DESC Help');
  281.  TextColor(NormFg);
  282.  GotoXY((ScreenWidth-41) DIV 2, 2); Write('USAGE:  4DESC [/help] [/mono] [d:][\path]');
  283.  
  284.  GotoXY( 8, 4); Write('UpArr, DnArr, PgUp, PgDn:  Move highlight bar');
  285.  GotoXY( 8, 5); Write('LtArr, RtArr, Home, End:   Move cursor');
  286.  GotoXY( 8, 6); Write('Ctrl-PgUp, Ctrl-PgDn:      Move to first or last line');
  287.  GotoXY( 8, 7); Write('Ctrl-Left, Ctrl-Right:     Move to previous/next word');
  288.  GotoXY( 8, 9); Write('Backspace:        Delete the character before the cursor');
  289.  GotoXY( 8,10); Write('DEL:              Delete the character under  the cursor');
  290.  GotoXY( 8,11); Write('Ctrl-End:         Delete from cursor to end of line');
  291.  GotoXY( 8,12); Write('INS:              Toggle from insert mode (default) to overwrite mode ');
  292.  GotoXY( 8,13); Write('Alt-D:            Delete current description');
  293.  GotoXY( 8,14); Write('Alt-C:            Copy current description to buffer');
  294.  GotoXY( 8,15); Write('Alt-M, Alt-T:     Move current description to buffer');
  295.  GotoXY( 8,16); Write('Alt-P:            Paste buffer to current description');
  296.  GotoXY( 8,17); Write('Alt-V, F3:        View higlighted file');
  297.  GotoXY( 8,18); Write('Alt-S, Shift-F10: Shell to (4)DOS');
  298.  GotoXY( 8,19); Write('Alt-X, ESC:       Exit program');
  299.  GotoXY( 8,20); Write('F4 or ENTER on dir :  Change to highlighted directory');
  300.  GotoXY( 8,21); Write('F5 or ENTER on ..  :  Change to parent directory');
  301.  GotoXY( 8,22); Write('F6 or Alt-L        :  Change drive');
  302.  
  303.  GotoXY((ScreenWidth-Length(Header1)) div 2 ,24); Write(Header1);
  304.  GotoXY((ScreenWidth-Length(Header2)) div 2 ,25); Write(Header2);
  305. (* GotoXY((ScreenWidth-24) div 2,25); Write('Press any key to return.'); *)
  306.  
  307.  Cursor := $2000; SetCursorShape(Cursor);   (* Hide cursor. *)
  308.  CheckKeyOrMouse;
  309. END; (* ShowHelp *)
  310.  
  311.  
  312. (* -------------------------------------------------------- Keyboard *)
  313.  
  314. FUNCTION GetKey: WORD;
  315.  
  316. VAR chlo, chhi : CHAR;
  317.  
  318. BEGIN
  319.  chlo := ReadKey;
  320.  IF chlo = #0 THEN chhi := ReadKey
  321.               ELSE chhi := #0;
  322.  GetKey := WORD(chhi) SHL 8 + BYTE(chlo);
  323. END;
  324.  
  325.  
  326. PROCEDURE ChooseColors(Monochrome: BOOLEAN);
  327.  
  328. BEGIN
  329.  IF Monochrome THEN
  330.   IF INIFileExists THEN
  331.    BEGIN
  332.     DirFg    := ReadSettingsColor('monodisplay','dirfg'   ,mo_DirFg);
  333.     StatusFg := ReadSettingsColor('monodisplay','statusfg',mo_StatusFg);
  334.     StatusBg := ReadSettingsColor('monodisplay','statusbg',mo_StatusBg);
  335.     SelectFg := ReadSettingsColor('monodisplay','selectfg',mo_SelectFg);
  336.     SelectBg := ReadSettingsColor('monodisplay','selectbg',mo_SelectBg);
  337.     HighFg   := ReadSettingsColor('monodisplay','highfg'  ,mo_HighFg);
  338.     NormFg   := ReadSettingsColor('monodisplay','normfg'  ,mo_NormFg);
  339.     NormBg   := ReadSettingsColor('monodisplay','normbg'  ,mo_NormBg);
  340.     WarnFg   := ReadSettingsColor('monodisplay','warnfg'  ,mo_WarnFg);
  341.     WarnBg   := ReadSettingsColor('monodisplay','warnbg'  ,mo_WarnBg);
  342.    END
  343.   ELSE
  344.    BEGIN
  345.     DirFg    := mo_DirFg;
  346.     StatusFg := mo_StatusFg; StatusBg := mo_StatusBg;
  347.     SelectFg := mo_SelectFg; SelectBg := mo_SelectBg;
  348.     HighFg   := mo_HighFg;
  349.     NormFg   := mo_NormFg;   NormBg   := mo_NormBg;
  350.     WarnFg   := mo_WarnFg;   WarnBg   := mo_WarnBg;
  351.    END
  352.  ELSE
  353.   IF INIFileExists THEN
  354.    BEGIN
  355.     DirFg    := ReadSettingsColor('colordisplay','dirfg'   ,co_DirFg);
  356.     StatusFg := ReadSettingsColor('colordisplay','statusfg',co_StatusFg);
  357.     StatusBg := ReadSettingsColor('colordisplay','statusbg',co_StatusBg);
  358.     SelectFg := ReadSettingsColor('colordisplay','selectfg',co_SelectFg);
  359.     SelectBg := ReadSettingsColor('colordisplay','selectbg',co_SelectBg);
  360.     HighFg   := ReadSettingsColor('colordisplay','highfg'  ,co_HighFg);
  361.     NormFg   := ReadSettingsColor('colordisplay','normfg'  ,co_NormFg);
  362.     NormBg   := ReadSettingsColor('colordisplay','normbg'  ,co_NormBg);
  363.     WarnFg   := ReadSettingsColor('colordisplay','warnfg'  ,co_WarnFg);
  364.     WarnBg   := ReadSettingsColor('colordisplay','warnbg'  ,co_WarnBg);
  365.    END
  366.   ELSE
  367.    BEGIN
  368.     DirFg    := co_DirFg;
  369.     StatusFg := co_StatusFg; StatusBg := co_StatusBg;
  370.     SelectFg := co_SelectFg; SelectBg := co_SelectBg;
  371.     HighFg   := co_HighFg;
  372.     NormFg   := co_NormFg;   NormBg   := co_NormBg;
  373.     WarnFg   := co_WarnFg;   WarnBg   := co_WarnBg;
  374.    END;
  375. END;
  376.  
  377. BEGIN
  378.  Get4DOSVer;
  379.  OrigCursor := GetCursorShape;
  380.  MaxLines   := Hi(WindMax)+1;
  381.  ScreenSize := MaxLines-4;
  382.  ScreenWidth:= Lo(WindMax)+1;
  383.  Monochrome := (LastMode = Mono);
  384.  line       := Chars('─',ScreenWidth-1);
  385.  
  386.  IF INIFileExists THEN
  387.   BEGIN
  388.    s := ReadSettingsString('generaldisplay','leftjust','n');
  389.    NotLeftJust := (s[1] = 'y');
  390.    s := ReadSettingsString('generaldisplay','fullsize','n');
  391.    FullSize := (s[1] = 'y');
  392.    s := ReadSettingsString('generaldisplay','hidden','n');
  393.    UseHidden:= (s[1] = 'y');
  394.    ListCmd := ReadSettingsString('generaldisplay','viewer','list')
  395.   END
  396.  ELSE
  397.   BEGIN
  398.    NotLeftJust:= FALSE;
  399.    FullSize   := FALSE;
  400.    UseHidden  := FALSE;
  401.    ListCmd    := 'list';
  402.   END;
  403. END.
  404.